home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import flash.display.*;
- import flash.filters.BitmapFilter;
- import flash.filters.ColorMatrixFilter;
- import flash.geom.Point;
- import flash.utils.Dictionary;
-
- [Embed(source="/_assets/assets.swf", symbol="Model")]
- public class Model extends MovieClip
- {
-
- public static const NUM_LAYERS:int = 12;
-
-
- internal var _dMountPoints:Dictionary;
-
- internal var _dParts:Dictionary;
-
- internal var _sPose:String = "1";
-
- internal var _pComposePosition:Point;
-
- internal var _bActive:Boolean = true;
-
- internal var _aLayers:Array;
-
- internal var _partBra:Part = null;
-
- public function Model()
- {
- var _loc1_:int = 0;
- var _loc2_:MovieClip = null;
- _dMountPoints = new Dictionary();
- _dParts = new Dictionary();
- _aLayers = new Array();
- _sPose = ModelPose.POSE_1;
- _pComposePosition = new Point();
- _partBra = null;
- _bActive = true;
- super();
- while(numChildren > 0)
- {
- removeChildAt(0);
- }
- _loc1_ = 0;
- while(_loc1_ < NUM_LAYERS)
- {
- _loc2_ = new MovieClip();
- _loc2_.x = 0;
- _loc2_.y = 0;
- addChild(_loc2_);
- _aLayers.push(_loc2_);
- _loc1_++;
- }
- }
-
- public static function extractFromStage(param1:DisplayObjectContainer) : Array
- {
- var _loc2_:int = 0;
- var _loc3_:Array = null;
- var _loc4_:DisplayObject = null;
- _loc2_ = 0;
- _loc3_ = new Array();
- _loc2_ = 0;
- while(_loc2_ < param1.numChildren)
- {
- if((_loc4_ = param1.getChildAt(_loc2_)) is Model)
- {
- _loc3_.push(_loc4_);
- }
- _loc2_++;
- }
- _loc3_.sortOn("name");
- return _loc3_;
- }
-
- public function isAttributePresentInCategory(param1:String, param2:String) : Boolean
- {
- var _loc3_:Part = null;
- for each(_loc3_ in _dParts)
- {
- if(_loc3_.Category.toLowerCase() == param2.toLowerCase() && _loc3_.Template.hasAttribute(param1))
- {
- return true;
- }
- }
- return false;
- }
-
- public function getPercentMatch(param1:Model) : Number
- {
- var _loc2_:int = 0;
- var _loc3_:int = 0;
- var _loc4_:Part = null;
- _loc2_ = 0;
- _loc3_ = 0;
- for each(_loc4_ in _dParts)
- {
- if(_loc4_.Layer > 0)
- {
- if(_loc4_.isEqual(param1.getPart(_loc4_.Category)))
- {
- _loc2_++;
- }
- _loc3_++;
- }
- }
- if(getPose() == param1.getPose())
- {
- _loc2_++;
- }
- _loc3_++;
- return _loc2_ / _loc3_;
- }
-
- public function getPose() : String
- {
- return _sPose;
- }
-
- public function setPose(param1:String) : void
- {
- var _loc2_:Part = null;
- _sPose = param1;
- for each(_loc2_ in _dParts)
- {
- if(_loc2_ != null)
- {
- _loc2_.Pose = _sPose;
- }
- }
- }
-
- public function clearAllParts() : void
- {
- var _loc1_:Array = null;
- var _loc2_:Part = null;
- _loc1_ = new Array();
- for each(_loc2_ in _dParts)
- {
- _loc1_.push(_loc2_);
- }
- for each(_loc2_ in _loc1_)
- {
- removePart(_loc2_.Category);
- }
- }
-
- public function get Active() : Boolean
- {
- return _bActive;
- }
-
- public function getCommonAttributes(param1:String) : Array
- {
- var _loc2_:Array = null;
- var _loc3_:Array = null;
- var _loc4_:PartTemplate = null;
- var _loc5_:int = 0;
- var _loc6_:int = 0;
- var _loc7_:Boolean = false;
- var _loc8_:PartAttribute = null;
- var _loc9_:PartTemplate = null;
- _loc2_ = new Array();
- _loc3_ = new Array();
- if(getPart("dress") != null && getPart("shoe") != null)
- {
- _loc3_.push(getPart("dress").Template);
- _loc3_.push(getPart("shoe").Template);
- }
- else
- {
- if(!(getPart("top") != null && getPart("bottom") != null && getPart("shoe") != null))
- {
- return _loc2_;
- }
- _loc3_.push(getPart("top").Template);
- _loc3_.push(getPart("bottom").Template);
- _loc3_.push(getPart("shoe").Template);
- }
- if(!(_loc4_ = _loc3_[0]).matchesTheme(param1))
- {
- return _loc2_;
- }
- _loc5_ = 0;
- while(_loc5_ < _loc4_.Attributes.length)
- {
- _loc7_ = true;
- if((_loc8_ = _loc4_.Attributes[_loc5_]).Score < 0)
- {
- _loc7_ = false;
- }
- if(param1.toLowerCase().indexOf(_loc8_.Name.toLowerCase()) != -1)
- {
- _loc7_ = false;
- }
- _loc6_ = 1;
- while(_loc6_ < _loc3_.length)
- {
- if(!(_loc9_ = _loc3_[_loc6_]).hasAttribute(_loc8_.Name))
- {
- _loc7_ = false;
- }
- _loc6_++;
- }
- if(_loc7_)
- {
- _loc2_.push(_loc8_.Name);
- }
- _loc5_++;
- }
- return _loc2_;
- }
-
- public function getLayers() : Array
- {
- return _aLayers;
- }
-
- public function addPart(param1:Part) : Part
- {
- var _loc2_:int = 0;
- var _loc3_:Boolean = false;
- var _loc4_:Part = null;
- _loc2_ = 0;
- _loc3_ = false;
- _loc4_ = _dParts[param1.Category] as Part;
- param1.Pose = this._sPose;
- if(_loc4_ != null)
- {
- _aLayers[_loc4_.Layer].removeChild(_loc4_);
- }
- _dParts[param1.Category] = param1;
- _aLayers[param1.Layer].addChild(param1);
- switch(param1.Category)
- {
- case "top":
- _loc3_ = true;
- case "bottom":
- removePart("dress",false);
- break;
- case "dress":
- removePart("top",false);
- removePart("bottom",false);
- _loc3_ = true;
- break;
- case "bra":
- _partBra = param1;
- if(getPart("top") != null || getPart("dress") != null)
- {
- _loc3_ = true;
- }
- break;
- case "body":
- if(_partBra != null)
- {
- _aLayers[_partBra.Layer].addChild(_partBra);
- }
- }
- if(_loc3_)
- {
- if(_partBra != null)
- {
- _partBra.visible = false;
- }
- }
- updateTuckIns();
- dispatchEvent(new ModelEvent(ModelEvent.MODEL_PART_CHANGED));
- return _loc4_;
- }
-
- public function calcScore(param1:Array) : int
- {
- var _loc2_:int = 0;
- var _loc3_:String = null;
- var _loc4_:Part = null;
- _loc2_ = 0;
- for each(_loc3_ in ["top","bottom","shoe","accessory"])
- {
- if((_loc4_ = getPart(_loc3_)) != null)
- {
- _loc2_ += _loc4_.Template.getScoreForList(param1);
- }
- }
- return _loc2_;
- }
-
- public function undress() : void
- {
- var _loc1_:Array = null;
- var _loc2_:Part = null;
- _loc1_ = new Array();
- for each(_loc2_ in _dParts)
- {
- if(_loc2_.Layer != 0)
- {
- _loc1_.push(_loc2_);
- }
- }
- for each(_loc2_ in _loc1_)
- {
- removePart(_loc2_.Category);
- }
- }
-
- public function set Active(param1:Boolean) : void
- {
- _bActive = param1;
- if(_bActive)
- {
- dispatchEvent(new ModelEvent(ModelEvent.MODEL_ACTIVE_CHANGED));
- }
- }
-
- public function clone(param1:Model) : void
- {
- var _loc2_:Part = null;
- clearAllParts();
- for each(_loc2_ in param1._dParts)
- {
- addPart(_loc2_.Template.createPart());
- }
- _pComposePosition = new Point(param1._pComposePosition.x,param1._pComposePosition.y);
- if(param1.getPart("bra") != null)
- {
- addPart(param1.getPart("bra").Template.createPart());
- }
- setPose(param1.getPose());
- }
-
- public function getPart(param1:String) : Part
- {
- return _dParts[param1] as Part;
- }
-
- public function set ComposePosition(param1:Point) : *
- {
- _pComposePosition = new Point(param1.x,param1.y);
- }
-
- protected function updateTuckIns() : void
- {
- var _loc1_:Part = null;
- var _loc2_:String = null;
- for each(_loc2_ in ["top","bottom"])
- {
- _loc1_ = getPart(_loc2_);
- if(_loc1_ != null)
- {
- _loc1_.updateTuckIn();
- }
- }
- }
-
- public function removePart(param1:String, param2:Boolean = true) : Part
- {
- var _loc3_:Part = null;
- _loc3_ = _dParts[param1] as Part;
- delete _dParts[param1];
- if(_loc3_ != null)
- {
- _aLayers[_loc3_.Layer].removeChild(_loc3_);
- if(param1 == "top" || param1 == "dress")
- {
- _partBra.visible = true;
- }
- dispatchEvent(new ModelEvent(ModelEvent.MODEL_PART_CHANGED));
- }
- updateTuckIns();
- return _loc3_;
- }
-
- public function pickupPart(param1:Point, param2:DisplayObjectContainer) : Part
- {
- var _loc3_:Part = null;
- var _loc4_:Part = null;
- var _loc5_:DisplayObjectContainer = null;
- var _loc6_:* = undefined;
- _loc3_ = null;
- for each(_loc4_ in _dParts)
- {
- if(_loc4_ != null)
- {
- if(_loc4_.hasPixel(param1.x,param1.y,param2) && _loc4_.Layer > 0)
- {
- if(_loc3_ == null)
- {
- _loc3_ = _loc4_;
- }
- else if(_loc4_.Layer > _loc3_.Layer)
- {
- _loc3_ = _loc4_;
- }
- }
- }
- }
- if(_loc3_ != null)
- {
- _loc5_ = null;
- _loc5_ = _loc3_.parent;
- do
- {
- _loc6_ = _loc5_.localToGlobal(new Point(0,0));
- _loc3_.x = _loc6_.x;
- _loc3_.y = _loc6_.y;
- }
- while((_loc5_ = _loc5_.parent) != param2);
-
- removePart(_loc3_.Category);
- _loc3_.Pose = ModelPose.DEFAULT;
- }
- return _loc3_;
- }
-
- protected function dumpFilters() : void
- {
- var _loc1_:BitmapFilter = null;
- var _loc2_:ColorMatrixFilter = null;
- if(filters != null)
- {
- for each(_loc1_ in filters)
- {
- trace(_loc1_);
- if(_loc1_ is ColorMatrixFilter)
- {
- trace("ColorMatrixFilter");
- _loc2_ = _loc1_ as ColorMatrixFilter;
- trace(_loc2_.matrix);
- }
- }
- }
- }
-
- public function isDressed() : Boolean
- {
- if(this.getPart("top") != null && this.getPart("bottom") != null && this.getPart("shoe") != null || this.getPart("dress") != null && this.getPart("shoe") != null)
- {
- return true;
- }
- return false;
- }
-
- public function get ComposePosition() : Point
- {
- return _pComposePosition;
- }
-
- public function hasPart(param1:Part) : Boolean
- {
- var _loc2_:Part = null;
- _loc2_ = getPart(param1.Category);
- if(_loc2_ != null)
- {
- if(_loc2_.Template == param1.Template)
- {
- return true;
- }
- }
- return false;
- }
-
- public function isAttributePresent(param1:String) : Boolean
- {
- var _loc2_:Part = null;
- for each(_loc2_ in _dParts)
- {
- if(_loc2_.Template.hasAttribute(param1))
- {
- return true;
- }
- }
- return false;
- }
- }
- }
-